<?php
namespace app\user\model;
use think\Model;
use think\model\concern\SoftDelete;
use app\common\model\Taocan;
use app\user\model\User;
use app\user\model\Shop;

class UserGroup extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;
    protected $globalScope = ['shop_id'];
    
    public function scopeShop_id($query)
    {
        $query->where('shop_id', ShopId());
    }
    
    //获取权限组列表
    static function list_to_level() {
        //$shop = Shop::where('id', ShopId())->find();
        //$rules = Taocan::where('id',$shop['taocan'])->value('rules');
        //$list = list_to_level(self::where('id','in',$rules)->order('id desc')->select());
        $list = list_to_level(self::order('id desc')->select());
        return $list;
    }
    
    //获取我的权限
    static function my_auth() {
        //查询我的分组
        $user = User::where('id', UserId())->find();
        $auth = self::where('id',$user['group_id'])->value('rules');
        return $auth;
    }
}